/**
* @file string_utils.h
*
* Copyright (c) Huawei Technologies Co., Ltd. 2019-2020. All rights reserved.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef STRING_UTILS_H
#define STRING_UTILS_H

#include <vector>
#include <string>
#include <sstream>
#include "graph/ascend_limits.h"
#include "graph/small_vector.h"
#include "common/log_inner.h"

namespace acl {
class StringUtils {
public:
    template<typename T>
    static std::string VectorToString(const std::vector<T> &values)
    {
        std::stringstream ss;
        ss << '[';
        const auto size = values.size();
        for (size_t i = 0U; i < size; ++i) {
            ss << values[i];
            if (i != (size - 1U)) {
                ss << ", ";
            }
        }
        ss << ']';
        return ss.str();
    }

    template<typename T>
    static std::string VectorToString(const ge::SmallVector<T, static_cast<size_t>(ge::kDefaultMaxInputNum)> &values)
    {
        std::stringstream ss;
        ss << '[';
        const auto size = values.size();
        for (size_t i = 0U; i < size; ++i) {
            ss << values[i];
            if (i != (size - 1U)) {
                ss << ", ";
            }
        }
        ss << ']';
        return ss.str();
    }

    template<typename T>
    static std::string VectorToString(const std::vector<std::vector<T>> &values)
    {
        if (values.empty()) {
            return "[]";
        }

        const auto size = values.size();
        std::stringstream ss;
        ss << '[';
        for (size_t i = 0U; i < size; ++i) {
            ss << '[';
            const auto &subVec = values[i];
            const auto subSize = subVec.size();
            for (size_t j = 0U; j < subSize; ++j) {
                ss << subVec[j];
                if (j != (subSize - 1U)) {
                    ss << ", ";
                }
            }
            ss << "]";
            if (i != (size - 1U)) {
                ss << ", ";
            }
        }
        ss << "]";
        return ss.str();
    }

    template<typename T>
    static std::string VectorToString(const std::vector<std::pair<T, T>> &values)
    {
        if (values.empty()) {
            return "[]";
        }

        const auto size = values.size();
        std::stringstream ss;
        ss << '[';
        for (size_t i = 0U; i < size; ++i) {
            ss << '[';
            ss << values[i].first;
            ss << ", ";
            ss << values[i].second;
            ss << "]";
            if (i != (size - 1U)) {
                ss << ", ";
            }
        }
        ss << "]";
        return ss.str();
    }

    static void Split(const std::string &str, const char_t delim, std::vector<std::string> &elems);

    static bool IsDigit(const std::string &str);
};
} // namespace acl

#endif // STRING_UTILS_H
